PATH![]() |
![]() ![]() |
If you can divide the computational work of your application into several similar portions, each of which takes about the same amount of time to complete, you can create as many tasks as the number of processors and divide the work evenly among the tasks ("divide and conquer"). An example would be a filtering task on a large image. You could divide the image into as many equal sections as there are processors and have each do a fraction of the total work.
This method for using Multiprocessing Services involves creating two buffers per task: one for receiving work requests and one for posting results. You can create these buffers using either message queues or semaphores.
As shown in Figure 2-3 , the application splits the data evenly among the tasks and posts a work request, which defines the work a task is expected to perform, to each task's input buffer. Each task asks for a work request from its input buffer, and blocks if none is available. When a request arrives, the task performs the required work and then posts a message to its output buffer indicating that it has finished and providing the application with the results.
Figure 2-3 Parallel tasks with parallel I/O buffers